package fy.hr.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import fy.config.FyConfig;
import fy.hr.bean.IntegralsBean;
import fy.util.DBUtil;
import fy.util.MyUtil;

public class IntegralsDao {
	private static Log log = LogFactory.getLog(IntegralsDao.class);
	private IntegralsBean integralsBean;
	private final static String INSERT_HI_PSNDOC_GRPDEF6 = "insert into hi_psndoc_grpdef6(Groupdef8,Groupdef9,Groupdef2,Groupdef1,Groupdef3,Groupdef4,pk_psndoc_sub,pk_psnbasdoc,Groupdef5) values (?,?,?,?,?,?,?,?,?)";
	private final static String INSERT_HI_PSNDOC_GRPDEF11 = "insert into hi_psndoc_grpdef6(Groupdef8,Groupdef9,Groupdef1,Groupdef7,pk_psnbasdoc,pk_psndoc_sub,Groupdef5) values (?,?,?,?,?,?,?)";
	private final static String INSERT_HI_PSNDOC_GRPDEF9 = "insert into hi_psndoc_grpdef9(Groupdef4,Groupdef2,Groupdef3,Groupdef1,pk_psnbasdoc,pk_psndoc_sub,Begindate,Enddate,Groupdef5) values (?,?,?,?,?,?,?,?,?)";

	private final static String INSERT_HI_PSNDOC_GRPDEF8 = "insert into hi_psndoc_grpdef8(Begindate,Enddate,Groupdef1,Groupdef2,pk_psnbasdoc,pk_psndoc_sub,Groupdef3) values (?,?,?,?,?,?,?)";
	private final static String INSERT_HI_PSNDOC_GRPDEF5 = "insert into hi_psndoc_grpdef5(Groupdef2,Groupdef3,Groupdef4,Groupdef10,pk_psnbasdoc,pk_psndoc_sub,Groupdef6,Groupdef1) values (?,?,?,?,?,?,?,?)";
	private final static String INSERT_HI_PSNDOC_GRPDEF5_1 = "insert into hi_psndoc_grpdef5(Groupdef7,Groupdef8,pk_psnbasdoc,pk_psndoc_sub,Groupdef9,Groupdef10,Groupdef6) values (?,?,?,?,?,?,?)";

	private final static String LOOKUP_PK_PSNBASDOC = "SELECT pk_psnbasdoc FROM bd_psndoc b WHERE b.PSNCODE=?";
	//ZZ_I_1奖惩
	private final static String hi_psndoc_enc="insert into hi_psndoc_enc(pk_psnbasdoc,vencourtype,dencourdate,vencourorg,groupdef3,groupdef5,pk_psndoc_sub,groupdef10,pk_psndoc,vencourmatter,groupdef4) values (?,?,?,?,?,?,?,?,?,?,?)";
	//通讯稿
	private final static String hi_psndoc_grpdef8="insert into hi_psndoc_grpdef8(pk_psnbasdoc,Groupdef5,Groupdef4,pk_psndoc_sub,groupdef2,groupdef6) values (?,?,?,?,?,?)";
	private final static String LOOKUP_PK_PSNDOC = "SELECT pk_psndoc FROM bd_psndoc b WHERE b.PSNCODE=?";
	
	private final static String INSERT_HI_PSNDOC_ENC="insert into hi_psndoc_enc(pk_psnbasdoc,groupdef4,vencourmatter,dencourdate,pk_psndoc,pk_psndoc_sub)values('?','?','?','?','?','?')";
	
	// 查下拉值 注意REF_ENUMID正式和测试不同
	private final static String LOOKUP_XIALA_XINGJI = "SELECT c.SHOWVALUE FROM  CTP_ENUM_ITEM  c WHERE c.ENUMVALUE=? AND c.REF_ENUMID=?";

	// ---------------------------------
	// private final static String LOOKUP_PK_PSNSDOC =
	// "SELECT pk_psnsdoc FROM bd_psndoc b WHERE b.PSNCODE=?";
	private final static String INSERT_OR_UPDAYE = "select pk_psnbasdoc from hi_psndoc_grpdef6 where pk_psnbasdoc=? and Groupdef7=?";
	private final static String UPDAYE_HI_PSNDOC_GRPDEF11 = "update hi_psndoc_grpdef6 set Groupdef8=?,Groupdef9=?,Groupdef6=?,Groupdef5=? where pk_psnbasdoc=? and Groupdef7=?";
	private final static String INSERT_HI_PSNDOC_GRPDEF4 = "insert into hi_psndoc_grpdef4(pk_psnbasdoc,Groupdef1,Groupdef2,Groupdef3,Groupdef4,Groupdef5,pk_psndoc_sub)values(?,?,?,?,?,?,?)";
	private final static String INSERT_OR_UPDAYE8 = "select pk_psnbasdoc from hi_psndoc_grpdef8 where pk_psnbasdoc=? and Groupdef3=?";
	private final static String UPDAYE_HI_PSNDOC_GRPDEF8 = "update hi_psndoc_grpdef8 set Enddate=? where pk_psnbasdoc=? and Groupdef1=? and Groupdef3=? and lastflag='Y'";

	public boolean insertStarA(short form_type) {

		boolean success = false;
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;

		try {
			conn = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());
			log.info("type = "+form_type);
			// conn.setAutoCommit(false);

			/*
			 * insertTbm_awayh(conn);
			 * 
			 * insertTbm_awayb(conn,accountID);
			 */
			if (form_type == 1) {
				// 五星班组-星级班组认证审批表
				insertHiPsndocGrpdef6(conn);
			} else if (form_type == 2) {
				// 五星班组-五大员
				insertHiPsndocGrpdef11(conn);
			} else if (form_type == 3) {
				// 专业传承
				insertHiPsndocGrpdef9(conn);
			} else if (form_type == 4) {
				// 社团
				insertHiPsndocGrpdef8(conn);

			} else if (form_type == 5) {
				// 创新改善项目职级积分分配审批表
				insertHiPsndocGrpdef5(conn);
			} else if (form_type == 6) {
				// 创新改善资格认证审批表
				insertHiPsndocGrpdef5_1(conn);
			} else if (form_type == 7) {
				// 一票否决
				oneout(conn);
			}else if(form_type==8){
				//创新改善资格认证审批表 
				hi_psndoc_enc(conn);
			}else if(form_type==9){
				//通讯稿
				hi_psndoc_grpdef8(conn);
			}else{
				System.out.println("DAO 没调到");
			}
			
			conn.commit();

			success = true;

		} catch (Exception e) {
			DBUtil.rollback(conn);
			/*
			 * StringBuilder sb = new StringBuilder().append("表单《") //
			 * .append(awayFormBean.getBillname())
			 * .append("》数据写入HR数据库失败，单据编号为：")
			 * //.append(this.awayFormBean.getAwayid()); log.error(sb, e);
			 */
			// System.out.println(sb);
			e.printStackTrace();

		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
			DBUtil.setAutoCommit(conn, true);
			DBUtil.close(conn);
		}

		return success;
	}

	// 五星班组-星级班组认证审批表
	private void insertHiPsndocGrpdef6(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		// Begindate,Enddate,Groupdef1,Groupdef2,Groupdef3,Groupdef4,pk_psndoc_sub,pk_psnbasdoc
		String banZu;
		try {
			pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF6);

			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {

				if (this.integralsBean.getGroupDef1List().get(i).equals("0")) {
					banZu = "一星班组";
				} else if (this.integralsBean.getGroupDef1List().get(i)
						.equals("1")) {
					banZu = "二星班组";
				} else if (this.integralsBean.getGroupDef1List().get(i)
						.equals("2")) {
					banZu = "三星班组";
				} else if (this.integralsBean.getGroupDef1List().get(i)
						.equals("3")) {
					banZu = "四星班组";
				} else if (this.integralsBean.getGroupDef1List().get(i)
						.equals("4")) {
					banZu = "五星班组";
				} else {
					banZu = "测试";
				}

				pst.setString(1, this.integralsBean.getBeginDateList().get(i));
				pst.setString(2, this.integralsBean.getEndDateList().get(i));

				// pst.setString(3,
				// this.integralsBean.getGroupDef1List().get(i));
				pst.setString(3, banZu);
				// 需要注意第二个参数
				pst.setString(
						4,
						getUnitCode(this.integralsBean.getGroupDef2List()
								.get(i), "4140935276677120538"));// 测试-5342343765039297995正式4140935276677120538
				pst.setString(
						5,
						getUnitCode(this.integralsBean.getGroupDef3List()
								.get(i), "-5911347960402722674"));// 测试-8671782632865775074正式-5911347960402722674
				pst.setString(6, this.integralsBean.getGroupDef4List().get(i));
				pst.setString(7, MyUtil.createUUID());
				pst.setString(
						8,
						judgmentCompany(this.integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC));
				pst.setString(9, "五星班组");
//				log.info(pst.toString());
				pst.addBatch();
			}
			log.info("pst:"+pst);
			pst.executeBatch();

		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}

	// 五星班组-五大员
	private void insertHiPsndocGrpdef11(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {

			// pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF11);

			// pst= conn.prepareStatement(UPDAYE_HI_PSNDOC_GRPDEF11);

			String jiesou = null;
			String position = null;

			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {

				if (this.integralsBean.getGroupDef3List().get(i).equals("0")) {
					position = "成本协管员";
				} else if (this.integralsBean.getGroupDef3List().get(i)
						.equals("1")) {
					position = "质量协管员";
				} else if (this.integralsBean.getGroupDef3List().get(i)
						.equals("2")) {
					position = "设备协管员";
				} else if (this.integralsBean.getGroupDef3List().get(i)
						.equals("3")) {
					position = "安全协管员";
				} else {
					position = "生活协管员";
				}

				log.info(judgmentCompany(this.integralsBean.getPersonCodeList()
						.get(i), LOOKUP_PK_PSNBASDOC)
						+ position);

				jiesou = getID(
						judgmentCompany(this.integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC), position);

				if (jiesou == null) {
					pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF11);
					pst.setString(1,
							this.integralsBean.getBeginDateList().get(i));
					pst.setString(2, this.integralsBean.getEndDateList().get(i));
					pst.setString(3,
							this.integralsBean.getGroupDef2List().get(i));
					pst.setString(4, position);
					pst.setString(
							5,
							judgmentCompany(integralsBean.getPersonCodeList()
									.get(i), LOOKUP_PK_PSNBASDOC));
					pst.setString(6, MyUtil.createUUID());
					// ------
					pst.setString(7, "五大员");
					pst.addBatch();
					log.info("pst:"+pst);
					pst.executeBatch();
				} else {

					pst = conn.prepareStatement(UPDAYE_HI_PSNDOC_GRPDEF11);
					pst.setString(1,
							this.integralsBean.getBeginDateList().get(i));
					pst.setString(2, this.integralsBean.getEndDateList().get(i));
					pst.setString(3,
							this.integralsBean.getGroupDef2List().get(i));

					// ------
					pst.setString(4, "五大员");
					pst.setString(
							5,
							judgmentCompany(integralsBean.getPersonCodeList()
									.get(i), LOOKUP_PK_PSNBASDOC));
					pst.setString(6, position);
					pst.addBatch();
					log.info("pst:"+pst);
					pst.executeBatch();
				}

				// pst.addBatch();
				// pst.executeBatch();
			}
			// pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}

	// 专业传承申报表
	private void insertHiPsndocGrpdef9(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		String emp = null;
		String emp2 = null;
		// Groupdef1,Groupdef2,Groupdef3,Groupdef4,pk_psnbasdoc,pk_psndoc_sub,Begindate,Enddate
		try {
			pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF9);

			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {

				pst.setString(1, this.integralsBean.getGroupDef1List().get(i));
				// HR需要什么 是否 还是 0/1
				// this.integralsBean.getGroupDef2List().get(i)
				if (this.integralsBean.getGroupDef2List().get(i).equals("0")) {
					emp = "Y";
				} else {
					emp = "N";
				}
				pst.setString(2, emp);
				pst.setString(
						3,
						getUnitCode(this.integralsBean.getGroupDef3List()
								.get(i), "5867075771443987116"));// 测试8311907047796002437正式5867075771443987116
				// this.integralsBean.getGroupDef4List().get(i)
				if (this.integralsBean.getGroupDef4List().get(i).equals("0")) {
					emp2 = "Y";
				} else {
					emp2 = "N";
				}
				pst.setString(4, emp2);
				pst.setString(
						5,
						judgmentCompany(this.integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC));
				pst.setString(6, MyUtil.createUUID());
				pst.setString(7, this.integralsBean.getBeginDateList().get(i));
				pst.setString(8, this.integralsBean.getEndDateList().get(i));
				pst.setString(9, this.integralsBean.getGroupDef5List().get(i));

				pst.addBatch();
			}
			log.info("pst:"+pst);
			pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}

	// 社团（文化贡献）
	private void insertHiPsndocGrpdef8(Connection conn) throws Exception {
		
		PreparedStatement pst = null;
		ResultSet rs = null;

		// Begindate,Enddate,Groupdef1,Groupdef2,pk_psnbasdoc,pk_psndoc_sub
		try {
			String jiesou = null;
			String SheTian = null;
			String SheTian2 = null;
			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {
				if (this.integralsBean.getGroupDef3List().get(i).equals("0")) {
					SheTian = "吉他社";
				} else if(this.integralsBean.getGroupDef3List().get(i).equals("1")){
					SheTian = "篮球社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("2")){
					SheTian = "乒乓球社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("3")){
					SheTian = "骑行社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("4")){
					SheTian = "舞蹈社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("5")){
					SheTian = "英语俱乐部";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("6")){
					SheTian = "瑜伽社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("7")){
					SheTian = "羽毛球社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("8")){
					SheTian = "约跑社";
				}else if(this.integralsBean.getGroupDef3List().get(i).equals("9")){
					SheTian = "足球社";
				}
				
				if (this.integralsBean.getGroupDef1List().get(i).equals("0")) {
					SheTian2 = "第一负责人";
				}else{
					SheTian2 = "第二负责人";
				}

//				log.info(judgmentCompany(this.integralsBean.getPersonCodeList()
//						.get(i), LOOKUP_PK_PSNBASDOC)
//						+ SheTian);

				jiesou = getID2(
						judgmentCompany(this.integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC), SheTian);

				if (jiesou == null) {
//					 System.out.println("123");
					pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF8);

					pst.setString(1,
							this.integralsBean.getBeginDateList().get(i).substring(0, 10));
					pst.setString(2, this.integralsBean.getEndDateList().get(i));

					pst.setString(3, SheTian2);
					pst.setString(4, "社团负责人");
					pst.setString(
							5,
							judgmentCompany(this.integralsBean
									.getPersonCodeList().get(i),
									LOOKUP_PK_PSNBASDOC));
					pst.setString(6, MyUtil.createUUID());
					// --------------------
					pst.setString(7,SheTian);
					pst.addBatch();
					log.info("pst:"+pst);
					pst.executeBatch();
				} else {
//					 System.out.println("321");
					pst = conn.prepareStatement(UPDAYE_HI_PSNDOC_GRPDEF8);
					pst.setString(1, this.integralsBean.getEndDateList().get(i).substring(0, 10));
					pst.setString(
							2,
							judgmentCompany(this.integralsBean
									.getPersonCodeList().get(i),
									LOOKUP_PK_PSNBASDOC));
					pst.setString(3, SheTian2);
					pst.setString(4, SheTian);
					pst.addBatch();
					log.info("pst:"+pst);
					pst.executeBatch();
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}

	// 创新改善项目职级积分分配审批表
	private void insertHiPsndocGrpdef5(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		// Groupdef1,Groupdef2,Groupdef3,Groupdef4,pk_psnbasdoc,pk_psndoc_sub
		try {

			pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF5);

			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {

				pst.setString(
						1,
						getUnitCode(this.integralsBean.getGroupDef1List()
								.get(i), "-2355918428318250561"));// 测试-1226391613162241560正式-2355918428318250561

				pst.setString(2, this.integralsBean.getGroupDef2List().get(i));

				pst.setString(
						3,
						getUnitCode(this.integralsBean.getGroupDef3List()
								.get(i), "-3479022351882040549"));// 测试-2634895003683241404正式-3479022351882040549
				pst.setString(4, this.integralsBean.getGroupDef4List().get(i));
				pst.setString(
						5,
						judgmentCompany(this.integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC));
				pst.setString(6, MyUtil.createUUID());
				// ----------------------------

//				pst.setString(7, this.integralsBean.getGroupDef6List().get(i));
				pst.setString(7, "创新改善项目");
				pst.setString(8, this.integralsBean.getGroupDef5List().get(i));
				log.info("pst:"+pst);
				pst.addBatch();
			}

			pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}

	// 创新改善资格认证审批表
	private void insertHiPsndocGrpdef5_1(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		// Begindate,Groupdef3,pk_psnbasdoc,pk_psndoc_sub
		try {
			pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF5_1);

			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {

				pst.setString(1, this.integralsBean.getBeginDateList().get(i));
				pst.setString(
						2,
						getUnitCode(this.integralsBean.getGroupDef3List()
								.get(i), "4839633989671011686"));// 测试-39122309441828334正式4839633989671011686
				pst.setString(
						3,
						judgmentCompany(this.integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC));
				pst.setString(4, MyUtil.createUUID());
				// ------------------------------
				pst.setString(5, this.integralsBean.getGroupDef5List().get(i));
				pst.setString(6, this.integralsBean.getGroupDef4List().get(i));
				pst.setString(7, "创新改善资格");
				log.info("pst:"+pst);
				pst.addBatch();
			}

			pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}

	// -------------------------------------------------
	// 一票否决
	private void oneout(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		// Begindate,Groupdef3,pk_psnbasdoc,pk_psndoc_sub
		String why = null;

		try {
			pst = conn.prepareStatement(INSERT_HI_PSNDOC_GRPDEF4);

			for (int i = 0, size = this.integralsBean.getPersonCodeList()
					.size(); i < size; i++) {
				pst.setString(
						1,
						judgmentCompany(integralsBean.getPersonCodeList()
								.get(i), LOOKUP_PK_PSNBASDOC));
				pst.setString(2, this.integralsBean.getBeginDateList().get(i));

				if (this.integralsBean.getGroupDef1List().get(i).equals("0")) {
					why = "安全";
				} else if (this.integralsBean.getGroupDef1List().get(i)
						.equals("1")) {
					why = "质量";
				} else {
					why = "员工违纪";
				}

				pst.setString(3, why);
				pst.setString(4, this.integralsBean.getGroupDef2List().get(i));
				pst.setString(5, this.integralsBean.getGroupDef3List().get(i));
				pst.setString(6, this.integralsBean.getGroupDef4List().get(i));
				pst.setString(7, MyUtil.createUUID());
				log.info("pst:"+pst);
				pst.addBatch();
			}

			pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}
	private void hi_psndoc_enc(Connection conn) throws Exception {
		log.info("123456");
		PreparedStatement pst = null;
		ResultSet rs = null;
		String type=null;
		String type2=null;
		String type3=null;
		//Begindate,Groupdef3,pk_psnbasdoc,pk_psndoc_sub
		try {
			pst = conn.prepareStatement(hi_psndoc_enc);

			for (int i = 0, size = this.integralsBean.getPersonCodeList().size(); i < size; i++) {
				
				pst.setString(1,judgmentCompany(this.integralsBean.getPersonCodeList().get(i), LOOKUP_PK_PSNBASDOC) );

				log.info("strp001");

				if(this.integralsBean.getGroupDef1List().get(i).equals("0")){
					type="奖";
				}else{
					type="惩";
				}
				log.info("strp002");
				pst.setString(2,type);
				pst.setString(3,this.integralsBean.getBeginDateList().get(i));
				if(this.integralsBean.getGroupDef2List().get(i).equals("0")){
					type3="董事长奖";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("1")){
					type3="总裁奖";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("2")){
					type3="子集团级";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("3")){
					type3="子公司级";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("4")){
					type3="工厂/部门级";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("5")){
					type3="车间级";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("6")){
					type3="市级及以上";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("7")){
					type3="开发区/县级";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("8")){
					type3="批评";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("9")){
					type3="警告";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("10")){
					type3="记小过";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("11")){
					type3="记大过";
				}else if(this.integralsBean.getGroupDef2List().get(i).equals("12")){
					type3="解聘";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("13")){
					type3="对标标杆-行业级";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("14")){
					type3="对标标杆-子集团级";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("15")){
					type3="对标标杆-工厂级";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("16")){
					type3="对标标杆-车间级";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("17")){
					type3="对标标杆-班组级";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("18")){
					type3="表扬/嘉奖";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("19")){
					type3="记小功";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("20")){
					type3="记功";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("21")){
					type3="记大功";
				}
				else if(this.integralsBean.getGroupDef2List().get(i).equals("22")){
					type3="记过";
				}
				log.info("strp003");
				pst.setString(4, type3);
				
				pst.setString(5,this.integralsBean.getGroupDef4List().get(i) );
				
				if(this.integralsBean.getGroupDef3List().get(i).equals("0")){
					type2="Y";
				}else{
					type2="N";
				}
				log.info("strp004");
				pst.setString(6,type2);
				log.info("strp0041");
				pst.setString(7,MyUtil.createUUID());
				log.info("strp0042");
				pst.setString(8,"OA");
				log.info("strp005");
				pst.setString(9,judgmentCompany(this.integralsBean.getPersonCodeList().get(i), LOOKUP_PK_PSNDOC));
				pst.setString(10,this.integralsBean.getGroupDef5List().get(i));
				log.info("strp006");
				pst.setString(11,this.integralsBean.getGroupDef7List().get(i));
				log.info("pst:"+pst);
				pst.addBatch();
			}

			pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}
	//通讯稿
	private void hi_psndoc_grpdef8(Connection conn) throws Exception {
		PreparedStatement pst = null;
		ResultSet rs = null;
		String type=null;
		//Begindate,Groupdef3,pk_psnbasdoc,pk_psndoc_sub
		try {
			pst = conn.prepareStatement(hi_psndoc_grpdef8);

			for (int i = 0, size = this.integralsBean.getPersonCodeList().size(); i < size; i++) {
				
				pst.setString(1,judgmentCompany(this.integralsBean.getPersonCodeList().get(i), LOOKUP_PK_PSNBASDOC));
				
				pst.setString(5,this.integralsBean.getGroupDef1List().get(i) );
				if(this.integralsBean.getGroupDef1List().get(i).equals("0")){
					type="0001N31000000002WUWC";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("1")){
					type="0001N31000000002WUWD";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("2")){
					type="0001N31000000002WUWH";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("3")){
					type="0001N31000000002WUWI";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("4")){
					type="0001N31000000002WUWJ";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("5")){
					type="0001N31000000002WUWK";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("6")){
					type="0001N31000000002WUX1";
				}else if(this.integralsBean.getGroupDef1List().get(i).equals("7")){
					type="0001N31000000002WUX2";
				}
		
				pst.setString(2,type);
				pst.setString(3,this.integralsBean.getBeginDateList().get(i));
				pst.setString(4, MyUtil.createUUID());
				pst.setString(5,"通讯稿" );
				pst.setString(6,"OA");
				log.info("pst:"+pst);
				pst.addBatch();
			}

			pst.executeBatch();

		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
	}
//	//稿子
//	private void insertHiPsndocENC(Connection conn) throws Exception {
//		PreparedStatement pst = null;
//		ResultSet rs = null;
//		//Begindate,Groupdef3,pk_psnbasdoc,pk_psndoc_sub
//		//INSERT INTO hi_psndoc_enc(pk_psnbasdoc,groupdef4,vencourmatter,dencourdate,pk_psndoc,pk_psndoc_sub)VALUES('?','?','?','?','?','?')
//		try {
//			pst = conn.prepareStatement(INSERT_HI_PSNDOC_ENC);
//
//			for (int i = 0, size = this.integralsBean.getPersonCodeList().size(); i < size; i++) {
//				
//				pst.setString(1, this.integralsBean.getBeginDateList().get(i));
//				pst.setString(2,getUnitCode(this.integralsBean.getGroupDef3List().get(i),"-39122309441828334"));
//				pst.setString(3, judgmentCompany(this.integralsBean.getPersonCodeList().get(i), LOOKUP_PK_PSNBASDOC));
//				pst.setString(4, MyUtil.createUUID());
//				pst.setString(5, judgmentCompany(this.integralsBean.getPersonCodeList().get(i), LOOKUP_PK_PSNBASDOC));
//				pst.setString(6, MyUtil.createUUID());
//				pst.addBatch();
//			}
//
//			pst.executeBatch();
//
//		} finally {
//			DBUtil.close(rs);
//			DBUtil.close(pst);
//		}
//	}
	// 查公司
	public String judgmentCompany(String code, String temp) throws Exception {
		String pk_corp = null;
		Connection conns;
		conns = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			pst = conns.prepareStatement(temp);
			pst.setString(1, code);
			rs = pst.executeQuery();
			while (rs.next()) {
				pk_corp = rs.getString(1);
			}

		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
		return pk_corp;
	}

	// 获取下拉值
	public String getUnitCode(String code, String temp) {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;

		try {
			conn = DBUtil.connect(FyConfig.getOA_DB_CONFIG());
			pst = conn.prepareStatement(LOOKUP_XIALA_XINGJI);
			pst.setString(1, code);
			pst.setString(2, temp);
			rs = pst.executeQuery();
			if (rs.next()) {
				code = rs.getString(1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs, pst);
		}
		return code;
	}
	// 五星班组用
	public String getID(String ID, String type) {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		String temp = null;
		String pk_psnbasdoc = null;

		try {
			conn = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());
			pst = conn.prepareStatement(INSERT_OR_UPDAYE);
			pst.setString(1, ID);
			pst.setString(2, type);
			rs = pst.executeQuery();

			if (rs.next()) {
				pk_psnbasdoc = rs.getString(1);

			}

			log.info(pk_psnbasdoc);
			/*
			 * if(!pk_psnbasdoc.equals("")){ temp=pk_psnbasdoc; }
			 */
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs, pst);
		}
		return pk_psnbasdoc;
	}

	// 社团用
	public String getID2(String ID, String type) {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		String temp = null;
		String pk_psnbasdoc = null;

		try {
			conn = DBUtil.connect(FyConfig.getEHR_DB_CONFIG());
			pst = conn.prepareStatement(INSERT_OR_UPDAYE8);
			pst.setString(1, ID);
			pst.setString(2, type);

			rs = pst.executeQuery();

			if (rs.next()) {
				pk_psnbasdoc = rs.getString(1);

			}

			log.info(pk_psnbasdoc);
			/*
			 * if(!pk_psnbasdoc.equals("")){ temp=pk_psnbasdoc; }
			 */
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs, pst);
		}
		return pk_psnbasdoc;
	}
	public void setIntegralsBean(IntegralsBean integralsBean) {
		this.integralsBean = integralsBean;
	}

}